package com.spzx.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.domain.CategoryBrand;
import com.spzx.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/categoryBrand")
@Tag(name = "分类品牌接口管理")
public class CategoryBrandController extends BaseController {
    @Resource
    CategoryBrandService categoryBrandService;

    @GetMapping("/list")
    @Operation(summary = "分页查询分类品牌")
    public TableDataInfo listCategoryBrand(CategoryBrand categoryBrand) {
        startPage();
        List<CategoryBrand> categoryBrands = categoryBrandService.listCategoryBrand(categoryBrand);
        //TableDataInfo tableDataInfo = new TableDataInfo(categoryBrands, categoryBrands.);
        return getDataTable(categoryBrands);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取分类品牌详细信息")
    public AjaxResult getDetails(@PathVariable Long id) {
        return AjaxResult.success(categoryBrandService.getCategoryBrandById(id));
    }

    @PostMapping
    @Operation(summary = "新增品牌分类")
    public AjaxResult insert(@RequestBody @Validated CategoryBrand categoryBrand) {
        return toAjax(categoryBrandService.insert(categoryBrand));
    }

    @PutMapping
    @Operation(summary = "修改分类品牌")
    public AjaxResult update(@RequestBody @Validated CategoryBrand categoryBrand) {
        return toAjax(categoryBrandService.updateCategoryBrand(categoryBrand));
    }

    @DeleteMapping("/{ids}")
    @Operation(summary = "删除分类品牌")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(categoryBrandService.removeBatchByIds(Arrays.stream(ids).toList()));
    }
   /* @GetMapping("/getByC3Id/{id}")
    @Operation(summary = "根据C3Id查询品牌列表")
    public AjaxResult getByC3Id(@PathVariable Long id){
        categoryBrandService.getByC3Id(id);
        return success();
    }*/


}
